//
//  LGNavigationController.m
//  微博
//
//  Created by MS on 15-12-4.
//  Copyright (c) 2015年 MS. All rights reserved.
//

#import "LGNavigationController.h"
#import "UIBarButtonItem+Item.h"
#import "UIImage+Image.h"
@interface LGNavigationController ()<UINavigationControllerDelegate>

@property (nonatomic,strong) id popDelegate;

@end

@implementation LGNavigationController

+ (void)initialize
{
    //获取当前类下面的UIBarButtonItem
    UIBarButtonItem * item = [UIBarButtonItem appearanceWhenContainedIn:self, nil];
    
    NSMutableDictionary * attributes = [NSMutableDictionary dictionary];
    attributes[NSForegroundColorAttributeName] = [UIColor orangeColor];
    
    [item setTitleTextAttributes:attributes forState:UIControlStateNormal];

}

-(void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    
  [super pushViewController:viewController animated:animated];

}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //实现滑动返回功能
    //清空滑动返回手势的代理就能实现
    
    self.popDelegate =self.interactivePopGestureRecognizer.delegate;
    
    
    self.delegate = self;
}

#pragma UINavigationControllerDelegate方法，导航控制器即将跳转时调用
-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
 //   LGLog(@"%@",viewController);
    
       
    if (viewController == self.viewControllers[0]) {//显示跟控制器
        
        self.interactivePopGestureRecognizer.delegate = self.popDelegate;
//         [navigationController setNavigationBarHidden:NO animated:animated];
        
    }
    else {//不是则清空
        
        self.interactivePopGestureRecognizer.delegate = nil;
//        [navigationController setNavigationBarHidden:YES animated:animated];
    }
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
